package com.tanhua.dubbo.server.controller;

import com.tanhua.dubbo.server.service.TanHuaService;
import com.tanhua.dubbo.server.vo.NearUserVo;
import com.tanhua.dubbo.server.vo.TodayBest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 *
 * @ClassName: TanHuaController
 * @Author:王晨晗
 * @Description: 探花功能
 * @Date: 2022/01/06/19:39
 */
@RequestMapping("tanhua")
@RestController
public class TanHuaController {
    @Autowired
    private TanHuaService tanHuaService;

    /**
     * @param userId
     * @return
     * @description 查询个人主页的个人信息
     */
    @GetMapping("{id}/personalInfo")
    public ResponseEntity<TodayBest> queryUserInfo(@PathVariable("id") Long userId) {
        TodayBest todayBest = tanHuaService.queryUserInfo(userId);
        return ResponseEntity.ok(todayBest);
    }

    /**
     * @param userId
     * @return
     * @description 查询用户的默聊问题
     */
    @GetMapping("strangerQuestions")
    public ResponseEntity<String> queryQuestion(@RequestParam("userId") Long userId) {
        String question = tanHuaService.queryQuestion(userId);
        return ResponseEntity.ok(question);
    }

    /**
     * @param param
     * @return
     * @description 回复用户的默聊问题
     */
    @PostMapping("strangerQuestions")
    public ResponseEntity<Void> replyQuestion(@RequestBody Map<String, Object> param) {
        Long userId = Long.valueOf(param.get("userId").toString());
        String reply = param.get("reply").toString();
        tanHuaService.replyQuestion(userId, reply);
        return ResponseEntity.ok(null);
    }


    /**
     * @description 搜索附近的人
     * @param gender
     * @param distance
     * @return
     */
    @GetMapping("search")
    public ResponseEntity queryNearUser(@RequestParam(value = "gender", required = false) String gender,
                                        @RequestParam(value = "distance", defaultValue = "2000") String distance){
        List<NearUserVo> list = tanHuaService.queryNearUser1(gender , distance);
        return ResponseEntity.ok(list);
    }

    /**
     * @return
     * @description 探花卡片列表
     */
    @GetMapping("cards")
    public ResponseEntity queryCardsList() {
        List<TodayBest> list = tanHuaService.queryCardsList();
        return ResponseEntity.ok(list);
    }

    /**
     * @param likeUserId
     * @return
     * @description 喜欢:右滑
     */
    @GetMapping("{id}/love")
    public ResponseEntity<Void> likeUser(@PathVariable("id") Long likeUserId) {
        tanHuaService.likeUser(likeUserId);
        return ResponseEntity.ok(null);
    }

    /**
     * @param likeUserId
     * @return
     * @description 不喜欢:左滑
     */
    @GetMapping("{id}/unlove")
    public ResponseEntity<Void> notLikeUser(@PathVariable("id") Long likeUserId) {
        tanHuaService.notLikeUser(likeUserId);
        return ResponseEntity.ok(null);
    }
}
